home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / sprite.X11R3 / hdr / pixrect.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-03  |  10.4 KB  |  337 lines

  1. /* @(#)pixrect.h 1.46 89/03/19 SMI */
  2.  
  3. /*
  4.  * Copyright 1986-1989 Sun Microsystems, Inc.
  5.  */
  6.  
  7. #ifndef    pixrect_DEFINED
  8. #define    pixrect_DEFINED
  9.  
  10. /*
  11.  * This file defines the programmer interface to the pixrect abstraction.
  12.  * A pixrect is a rectangular array of pixels on which a number of
  13.  * operations are defined.
  14.  *
  15.  * Each pixrect has as visible attributes its height and width in
  16.  * pixels and the number of bits stored for each pixel.  It also supports
  17.  * several operations.  The proper way to think of the operations is
  18.  * that they are messages sent to the pixrect.  The operations are:
  19.  *
  20.  *    pr_destroy    Destroy a pixrect.
  21.  *    pr_rop        Raster operation from another pixrect to the
  22.  *            destination pixrect.  The case where the source
  23.  *            and destination overlap is properly handled.
  24.  *    pr_stencil    Raster operation from source pixrect to the
  25.  *            dest pixrect using a stencil pixrect as a 'cookie
  26.  *            cutter' to perform a spatial write enable.
  27.  *    pr_batchrop    Like pr_rop, but source is an array of pixrects,
  28.  *            and an offset to be applied before each pixrect.
  29.  *            This is specifically designed for operations like
  30.  *            putting up text, which consists of a number of
  31.  *            characters from a font, each given by a pixrect.
  32.  *    pr_get        Get the value of a single pixel from a pixrect.
  33.  *    pr_put        Change a single pixel value in a pixrect.
  34.  *    pr_vector    Draw a vector in a pixrect
  35.  *    pr_region    Create a new pixrect which describes a rectangular
  36.  *            sub-region of an existing pixrect.
  37.  *    pr_putcolormap    Write a portion of the colormap.
  38.  *    pr_getcolormap    Read a portion of the colormap.
  39.  *    pr_putattributes Set the plane mask.
  40.  *    pr_getattributes Get the plane mask.
  41.  */
  42.  
  43. /*
  44.  * There are a number of structures used in the arguments to pixrects:
  45.  *
  46.  *    struct pr_pos        A position within a pixrect is a pair of
  47.  *                integers giving the offset from the upper
  48.  *                left corner.  The pixels within a pixrect
  49.  *                are numbered with (0,0) at the upper left
  50.  *                and (width-1,height-1) at the lower right.
  51.  *    struct pr_prpos        A pixrect and a position within it.
  52.  *    struct pr_size        A pair of integers representing the
  53.  *                size of a rectangle within a pixrect.
  54.  *    struct pr_subregion    A pixrect, a position and a size,
  55.  *                specifying a rectangular sub-region.
  56.  */
  57.  
  58. struct pr_size {
  59.     int    x, y;
  60. };
  61.  
  62. typedef struct pixrect {
  63.     struct    pixrectops *pr_ops;    /* operations appropriate to this pr */
  64.     struct    pr_size pr_size;    /* pixels per dimension */
  65.     int    pr_depth;        /* bits per pixel */
  66.     caddr_t    pr_data;        /* device-dependent data */
  67. } Pixrect;
  68. #define    pr_width    pr_size.x
  69. #define    pr_height    pr_size.y
  70.  
  71. struct pr_pos {
  72.     int    x, y;
  73. };
  74.  
  75. struct pr_prpos {
  76.     Pixrect *pr;
  77.     struct    pr_pos pos;
  78. };
  79.  
  80. struct pr_subregion {
  81.     Pixrect *pr;
  82.     struct    pr_pos pos;
  83.     struct    pr_size size;
  84. };
  85.  
  86. /* structure used to specify a single color */
  87. struct    singlecolor {
  88.     u_char    red, green, blue;
  89. };
  90.  
  91. /*
  92.  * Pr_product is used when doing multiplications involving pixrects,
  93.  * and casts its arguments to that the compiler will use 16 by 16 multiplies.
  94.  */
  95. #ifndef pr_product
  96. #if defined(sun) && !defined(sparc)
  97. #define    pr_product(a, b)    ((short)(a) * (short)(b))
  98. #else
  99. #define    pr_product(a, b)    ((a) * (b))
  100. #endif
  101. #endif
  102.  
  103. #ifndef KERNEL
  104. /*
  105.  * Takes device file name.  This is how a screen pixrect is created.
  106.  */
  107. extern Pixrect *pr_open();
  108. #endif !KERNEL
  109.  
  110. /*
  111.  * Pixrect ops vector, used by pr_ macros below to call the appropriate
  112.  * device dependent function for the destination pixrect.
  113.  */
  114. struct pixrectops {
  115.     int    (*pro_rop)();
  116. #ifndef KERNEL
  117.     int    (*pro_stencil)();
  118.     int    (*pro_batchrop)();
  119.     int    (*pro_nop)();        /* place holder */
  120.     int    (*pro_destroy)();
  121.     int    (*pro_get)();
  122.     int    (*pro_put)();
  123.     int    (*pro_vector)();
  124.     Pixrect * (*pro_region)();
  125. #endif !KERNEL
  126.     int    (*pro_putcolormap)();
  127. #ifndef KERNEL
  128.     int    (*pro_getcolormap)();
  129. #endif !KERNEL
  130.     int    (*pro_putattributes)();
  131. #ifndef KERNEL
  132.     int    (*pro_getattributes)();
  133. #endif !KERNEL
  134. };
  135.  
  136. #if !defined(lint) || defined(KERNEL)
  137.  
  138. #define    pr_rop(dpr, dx, dy, w, h, op, spr, sx, sy) \
  139.     (*(dpr)->pr_ops->pro_rop)((dpr), (dx), (dy), (w), (h), (op), \
  140.         (spr), (sx), (sy))
  141. #define    pr_putcolormap(pr, ind, cnt, red, grn, blu) \
  142.     (*(pr)->pr_ops->pro_putcolormap)((pr), (ind), (cnt), \
  143.         (red), (grn), (blu))
  144. #define    pr_putattributes(pr, planes) \
  145.     (*(pr)->pr_ops->pro_putattributes)((pr), (planes))
  146.  
  147. #ifndef KERNEL
  148.  
  149. #define    pr_stencil(dpr, dx, dy, w, h, op, stpr, stx, sty, spr, sx, sy) \
  150.     (*(dpr)->pr_ops->pro_stencil)((dpr), (dx), (dy), (w), (h), (op), \
  151.         (stpr), (stx), (sty), (spr), (sx), (sy))
  152. #define    pr_batchrop(dpr, x, y, op, sbp, n) \
  153.     (*(dpr)->pr_ops->pro_batchrop)((dpr), (x), (y), (op), (sbp), (n))
  154. #define    pr_destroy(pr) \
  155.     (*(pr)->pr_ops->pro_destroy)(pr)
  156. #define    pr_get(pr, x, y) \
  157.     (*(pr)->pr_ops->pro_get)((pr), (x), (y))
  158. #define    pr_put(pr, x, y, val) \
  159.     (*(pr)->pr_ops->pro_put)((pr), (x), (y), (val))
  160. #define    pr_vector(pr, x0, y0, x1, y1, op, color) \
  161.     (*(pr)->pr_ops->pro_vector)((pr), (x0), (y0), (x1), (y1), (op), \
  162.         (color))
  163. #define    pr_region(pr, x, y, w, h) \
  164.     (*(pr)->pr_ops->pro_region)((pr), (x), (y), (w), (h))
  165. #define    pr_getcolormap(pr, ind, cnt, red, grn, blu) \
  166.     (*(pr)->pr_ops->pro_getcolormap)((pr), (ind), (cnt), \
  167.         (red), (grn), (blu))
  168. #define    pr_getattributes(pr, planes) \
  169.     (*(pr)->pr_ops->pro_getattributes)((pr), (planes))
  170. #endif !KERNEL
  171.  
  172. #else !lint || KERNEL
  173.  
  174. extern pr_rop();
  175. extern pr_stencil();
  176. extern pr_batchrop();
  177. extern pr_destroy();
  178. extern pr_get();
  179. extern pr_put();
  180. extern pr_vector();
  181. extern Pixrect *pr_region();
  182. extern pr_putcolormap();
  183. extern pr_getcolormap();
  184. extern pr_putattributes();
  185. extern pr_getattributes();
  186.  
  187. #endif lint
  188.  
  189. /*
  190.  * Several of the above operations return a common, distinguished value when
  191.  * an error arises.  That value is defined as follows:
  192.  */
  193. #define    PIX_ERR    -1
  194.  
  195. /*
  196.  * Operations.  The 'op' in 'rasterop' may be any binary Boolean function, 
  197.  * encoded as an integer from 0 to 15 (the op code) shifted left by one bit.  
  198.  * The function is applied per-pixel.  
  199.  *
  200.  * The following permit the op to be expressed as Boolean combinations
  201.  * of the two inputs 'src' and 'dst'.  Thus oring the source and destination
  202.  * together is written as PIX_SRC|PIX_DST, while xoring the source with the
  203.  * destination is PIX_SRC^PIX_DST.  Since ~op would set the color and clip
  204.  * bits, the macro PIX_NOT is provided for use in place of ~.
  205.  */
  206. #define    PIX_SRC        (0xC << 1)
  207. #define    PIX_DST        (0xA << 1)
  208. #define    PIX_NOT(op)    ((op) ^ 0x1E)
  209. #define    PIX_CLR        (0x0 << 1)
  210. #define    PIX_SET        (0xF << 1)
  211.  
  212. /* macros which tell whether a rasterop needs SRC or DST values */
  213. #define    PIXOP_NEEDS_DST(op)    ((((op)>>1)^(op)) & PIX_NOT(PIX_DST))
  214. #define    PIXOP_NEEDS_SRC(op)    ((((op)>>2)^(op)) & PIX_NOT(PIX_SRC))
  215.  
  216. /* macros for encoding and extracting color field */
  217. #define    PIX_COLOR(c)    ((c)<<5)
  218. #define    PIX_OPCOLOR(op)    ((op)>>5)
  219.  
  220. /*
  221.  * The pseudo-operation PIX_DONTCLIP specifies that clipping should not
  222.  * be performed.  PIX_CLIP is also provided, although unnecessary.
  223.  */
  224. #define    PIX_DONTCLIP        0x1
  225. #define    PIX_CLIP        0x0
  226.  
  227. /*
  228.  * The following structured definitions, all prefixed with prs_, correspond
  229.  * to the unstructured definitions above prefixed with pr_.
  230.  */
  231.  
  232. #if !defined(lint) || defined(KERNEL)
  233.  
  234. #define    prs_rop(dstreg, op, srcprpos) \
  235.     pr_rop((dstreg).pr, (dstreg).pos.x, (dstreg).pos.y, \
  236.         (dstreg).size.x, (dstreg).size.y, (op), \
  237.         (srcprpos).pr, (srcprpos).pos.x, (srcprpos).pos.y)
  238. #define    prs_stencil(dstreg, op, stenprpos, srcprpos) \
  239.     pr_stencil((dstreg).pr, (dstreg).pos.x, (dstreg).pos.y, \
  240.         (dstreg).size.x, (dstreg).size.y, (op), \
  241.         (stenprpos).pr, (stenprpos).pos.x, (stenprpos).pos.y, \
  242.         (srcprpos).pr, (srcprpos).pos.x, (srcprpos).pos.y)
  243. #define    prs_batchrop(dstprpos, op, items, n) \
  244.     pr_batchrop((dstprpos).pr, (dstprpos).pos.x, (dstprpos).pos.y, \
  245.         (op), (items), (n))
  246. #define    prs_destroy(pr)        pr_destroy(pr)
  247. #define    prs_get(srcprpos) \
  248.     pr_get((srcprpos).pr, (srcprpos).pos.x, (srcprpos).pos.y)
  249. #define    prs_put(dstprpos, val) \
  250.     pr_put((dstprpos).pr, (dstprpos).pos.x, (dstprpos).pos.y, (val))
  251. #define    prs_vector(pr, pos0, pos1, op, color) \
  252.     pr_vector((pr), (pos0).x, (pos0).y, (pos1).x, (pos1).y, (op), (color))
  253. #define    prs_region(dstreg) \
  254.     pr_region((dstreg).pr, (dstreg).pos.x, (dstreg).pos.y, \
  255.         (dstreg).size.x, (dstreg).size.y)
  256. #define    prs_putcolormap(pr, ind, cnt, red, grn, blu) \
  257.     pr_putcolormap((pr), (ind), (cnt), (red), (grn), (blu))
  258. #define    prs_getcolormap(pr, ind, cnt, red, grn, blu) \
  259.     pr_getcolormap((pr), (ind), (cnt), (red), (grn), (blu))
  260. #define    prs_putattributes(pr, planes)    pr_putattributes((pr), (planes))
  261. #define    prs_getattributes(pr, planes)    pr_getattributes((pr), (planes))
  262.  
  263. /* pr_replrop is not currently in the ops vector */
  264. #define    prs_replrop(dstreg, op, srcprpos) \
  265.     pr_replrop((dstreg).pr, (dstreg).pos.x, (dstreg).pos.y, \
  266.         (dstreg).size.x, (dstreg).size.y, (op), \
  267.         (srcprpos).pr, (srcprpos).pos.x , (srcprpos).pos.y )
  268.  
  269. /* pr_close is a synonym for pr_destroy */
  270. #define    pr_close(pr)    pr_destroy(pr)
  271.  
  272. /* textured line macro */
  273. #define    pr_line(pr, x0, y0, x1, y1, brush, tex, op) \
  274.     pro_line((pr), (x0), (y0), (x1), (y1), (brush), (tex), (op), 0) 
  275.  
  276. #else !lint || KERNEL
  277.  
  278. extern prs_rop();
  279. extern prs_stencil();
  280. extern prs_batchrop();
  281. extern prs_destroy();
  282. extern prs_get();
  283. extern prs_put();
  284. extern prs_vector();
  285. extern Pixrect *prs_region();
  286. extern prs_putcolormap();
  287. extern prs_getcolormap();
  288. extern prs_putattributes();
  289. extern prs_getattributes();
  290.  
  291. extern prs_replrop();
  292. extern pr_close();
  293. extern pr_line();
  294.  
  295. #endif !lint || KERNEL
  296.  
  297.  
  298. #ifndef PR_NO_24BIT
  299. /*
  300.  * This gunk is for the cg8 and similar 24 bit + overlay frame buffers.
  301.  * It shouldn't be in this file, but it's too late to take it out now.
  302.  */
  303.  
  304. /*
  305.  * magic flag passed to true color frame buffer to force updating the
  306.  * colormap.  Yes, a kludge.
  307.  * Value defined to be the same as PIX_DONT_SET_PLANES purposedly
  308.  * [sic]
  309.  */
  310. #define    PR_FORCE_UPDATE    (1 << 24)
  311.  
  312. /* structure used to specify fields in a 32-bit pixel */
  313. union fbunit {
  314.     unsigned int    packed;           /* whole-sale deal */
  315.     struct {
  316.     unsigned int    A:8;           /* unused, for now */
  317.     unsigned int    B:8;           /* blue channel */
  318.     unsigned int    G:8;           /* green channel */
  319.     unsigned int    R:8;           /* red channel */
  320.     }               channel;           /* access per channel */
  321. };
  322.  
  323. #define    pr_putlut(pr, ind, cnt, red, grn, blu) \
  324.     (*(pr)->pr_ops->pro_putcolormap)((pr), PR_FORCE_UPDATE | (ind), \
  325.         (cnt), (red), (grn), (blu))
  326.  
  327. #ifndef KERNEL
  328. #define    pr_getlut(pr, ind, cnt, red, grn, blu) \
  329.     (*(pr)->pr_ops->pro_getcolormap)((pr), PR_FORCE_UPDATE | (ind), \
  330.         (cnt), (red), (grn), (blu))
  331. #endif !KERNEL
  332.  
  333. #endif PR_NO_24BIT
  334.  
  335.  
  336. #endif    pixrect_DEFINED
  337.